var Db = require('../../public/javascripts/Db')
var express = require('express');
var router = express.Router();
var endMassage = require('../../public/javascripts/endMassage')

//省市县接口
router.get('/getPCACode', (req, res) => {
    let { code } = req.query
    if (!code) {
        Db.DBFun('select pro_name,pro_id,id from pros', data => {
            res.send(endMassage({ data: '查询省级成功', list: data }))
        })
    } else {
        if (code.length != 6) {
            res.send(endMassage({ data: '查询成功', list: [] }))
        }
        if (code.includes('0000')) {
            Db.DBFun(`select city_name,city_id,pro_id,id from cities where pro_id='${code}'`, data => {
                res.send(endMassage({ data: '查询市级成功', list: data }))
            })
        } else if (code.includes('00')) {
            Db.DBFun(`select area_name,area_id,city_id,id from areas where city_id='${code}'`, data => {
                res.send(endMassage({ data: '查询县级成功', list: data }))
            })
        }
    }
})
module.exports = router